/**
 * 
 * Copyright 2009 Marco Speranza <marco.speranza79@gmail.com>
 *    
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *   
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.commons.database.util.jquerycreator;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

// TODO: Auto-generated Javadoc
/**
 * Utilit&agrave; di uso comune per lavorare con API JDBC.
 * 
 * @author Marco Speranza
 */
public final class JdbcUtils {

    /**
     * Chiude il <code>ResultSet</code>, se non &egrave; <code>null</code>.
     * 
     * @param rs
     *            Il <code>ResultSet</code> da chiudere
     * 
     * @throws SQLException
     *             the SQL exception
     */
    public static void close(final ResultSet rs) throws SQLException {
	if (rs != null) {
	    rs.close();
	}
    }

    /**
     * Chiude lo <code>Statement</code>, se non &egrave; <code>null</code>.
     * 
     * @param stmt
     *            Lo <code>Statement</code> da chiudere
     * 
     * @throws SQLException
     *             the SQL exception
     */
    public static void close(final Statement stmt) throws SQLException {
	if (stmt != null) {
	    stmt.close();
	}
    }

    /**
     * Chiude il <code>ResultSet</code> e lo <code>Statement</code> se non sono
     * <code>null</code>.
     * 
     * @param rs
     *            Il <code>java.sql.ResultSet</code> da chiudere
     * @param stmt
     *            Il <code>java.sql.Statement</code> da chiudere
     * 
     * @throws SQLException
     *             the SQL exception
     */
    public static void close(final ResultSet rs, final Statement stmt)
	    throws SQLException {
	close(rs);
	close(stmt);
    }

}